package cn.ld.module.infra.dal.mapper.config;

import cn.ld.framework.common.pojo.PageResult;
import cn.ld.framework.mybatis.core.mapper.BaseMapperX;
import cn.ld.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.ld.module.infra.controller.admin.config.vo.ConfigPageInVO;
import cn.ld.module.infra.dal.entity.config.ConfigEntity;
import org.apache.ibatis.annotations.Mapper;

@Mapper
public interface ConfigMapper extends BaseMapperX<ConfigEntity> {

    default ConfigEntity selectByKey(String key) {
        return selectOne(ConfigEntity::getConfigKey, key);
    }

    default PageResult<ConfigEntity> selectPage(ConfigPageInVO inVO) {
        return selectPage(inVO, new LambdaQueryWrapperX<ConfigEntity>()
                .likeIfPresent(ConfigEntity::getName, inVO.getName())
                .likeIfPresent(ConfigEntity::getConfigKey, inVO.getKey())
                .eqIfPresent(ConfigEntity::getType, inVO.getType())
                .betweenIfPresent(ConfigEntity::getCreateTime, inVO.getCreateTime()));
    }

}
